package JUnit;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.junit.Before;
import org.junit.Test;

import GamePackage.Blocks;
import GamePackage.Epoch;
import GamePackage.Initialize;
import GamePackage.Player;
import GamePackage.Tile;
import GamePackage.XmlOperation;

/**
 * Checks out how the xml files are generated initially.
 * 
 * @author ASPIRE
 * 
 */
public class InitializeTest {

	Initialize obj = new Initialize();
	List<Player> player_list = new ArrayList<Player>();
	List<Blocks> block_list = new ArrayList<Blocks>();
	List<Tile> tile_list = new ArrayList<Tile>();
	List<Epoch> epoch_list = new ArrayList<Epoch>();
	int rank1_castle, rank2_castle, rank3_castle, rank4_castle;
	Random generator = new Random();

	@Before
	public void setUp() throws Exception {
		obj.InitializeAll(1);
		player_list = XmlOperation.ReadXML();
		block_list = XmlOperation.ReadBlockXML();
		tile_list = XmlOperation.ReadTileXML();
		epoch_list = XmlOperation.ReadEpochXML();
		rank1_castle = player_list.get(0).getRank1_castle();
		rank2_castle = player_list.get(0).getRank2_castle();
		rank3_castle = player_list.get(0).getRank3_castle();
		rank4_castle = player_list.get(0).getRank4_castle();
	}

	@Test
	public final void testSetBoardToInitialSizeCheck() {
		assertEquals("Size of the block list extracted from xml should be 30",
				block_list.size(), 30);
	}

	@Test
	public final void testSetBoardToInitial() {
		assertEquals("Castle ranks should be 0 initially in every block", 0,
				block_list.get(generator.nextInt(30)).getCastle_rank());
		assertEquals("Player IDs should be 0 initially in every block", 0,
				block_list.get(generator.nextInt(30)).getPlayer_id());
		assertEquals("RBV should be 0 initially in every block", 0, block_list
				.get(generator.nextInt(30)).getRow_base_value());
		assertEquals("CBV should be 0 initially in every block", 0, block_list
				.get(generator.nextInt(30)).getColumn_base_value());

	}

	@Test
	public final void testSetPlayersToInitials() {
		new Initialize().setPlayersToInitials(false, 4);
		XmlOperation.WriteXML(player_list);
		// assertEquals("4 objects should be written into XML", 4,
		// player_list.size());

	}

	@Test
	public final void testSetScoreToInitial() {
		assertEquals("Size of the epoch list extracted from xml should be 6",
				6, epoch_list.size());
	}

}
